package mapEditor.data
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import mapEditor.vo.MapTerrainTileVO;
	import mapEditor.vo.MapVO;

	public class ConfigTemplateInfo extends EventDispatcher
	{
		private var _templateXml:XML;
		/**
		 *地图数据 
		 */		
		private var _mapVO:MapVO;
		
		public function ConfigTemplateInfo()
		{
			_mapVO=new MapVO();
		}
		
		private static var _instance:ConfigTemplateInfo;
		public static function get instance():ConfigTemplateInfo
		{
			if(_instance == null)
			{
				_instance = new ConfigTemplateInfo();
			}
			return _instance;
		}
		
		public function register(xml:XML):void
		{
			dispose();
			
			_templateXml=xml;
			_mapVO.tileSize=int(xml.size.@tile);
			_mapVO.mapCols=int(xml.size.@cols);
			_mapVO.mapRow=int(xml.size.@row);
			
			for each(var xmlItem:XML in xml.terrain.item)
			{
				var mapTerrainTileVO:MapTerrainTileVO=new MapTerrainTileVO();
				mapTerrainTileVO.x=int(xmlItem.@cols);
				mapTerrainTileVO.y=int(xmlItem.@row);
				mapTerrainTileVO.walkable=xmlItem.@walkable=="1";
				mapTerrainTileVO.height=int(xmlItem.@height);
				_mapVO.terrainTileList.push(mapTerrainTileVO);
			}
			
			dispatchEvent(new Event(Event.CHANGE));
		}
		
		/**
		 *地图数据 
		 * @return 
		 * 
		 */		
		public function get mapVO():MapVO
		{
			return _mapVO;
		}
		
		/**
		 *地图数据 
		 * @param value
		 * 
		 */		
		public function set mapVO(value:MapVO):void
		{
			_mapVO = value;
		}
		
		public function dispose():void
		{
			_templateXml=null;
		}
	}
}